package com.jyxd.web.service.patient;

import com.jyxd.web.dao.patient.PatientDiagnosisDao;
import com.jyxd.web.data.dto.HttpResult;
import com.jyxd.web.data.patient.PatientDiagnosis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

import static com.jyxd.web.util.ExecuteUtil.errorIfEmpty;

@Service
public class PatientDiagnosisService {

    @Autowired
    private PatientDiagnosisDao patientDiagnosisDao;

    /**
     * 新增一条信息
     *
     * @param
     * @return
     */
    public boolean insert(PatientDiagnosis patientDiagnosis) {
        return patientDiagnosisDao.insert(patientDiagnosis);
    }


    /**
     * 根据主键id查询一条记录
     *
     * @param id
     * @return Role
     */
    public PatientDiagnosis queryData(String id) {
        return patientDiagnosisDao.queryData(id);
    }

    /**
     * 根据患者id查询一条记录
     *
     * @param
     * @return Role
     */
    public HttpResult queryDataByPatientId(Map<String, Object> map) {
        errorIfEmpty(map, "请求参数不能为空");
        errorIfEmpty(map.get("patientId"), "查询患者id不能为空");
        String patientId = (String) map.get("patientId");
        PatientDiagnosis patientDiagnosis = patientDiagnosisDao.queryDataByPatientId(patientId);
        if (Objects.isNull(patientDiagnosis))
            return new HttpResult(200, "患者诊断不存在");
        return new HttpResult(200, patientDiagnosis, "诊断数据查询成功");
    }


    /**
     * 更新一条表记录
     *
     * @param patientDiagnosis
     * @return boolean
     */
    public boolean update(PatientDiagnosis patientDiagnosis) {
        return patientDiagnosisDao.update(patientDiagnosis);
    }


    /**
     * 根据条件分页查询表记录列表
     *
     * @param map
     * @return list
     */
    public List<PatientDiagnosis> queryList(Map<String, Object> map) {
        return patientDiagnosisDao.queryList(map);
    }


    public int batchInsert(List<PatientDiagnosis> list) {
        return patientDiagnosisDao.batchInsert(list);
    }
}
